﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YunLian.Cache.Internal;

namespace YunLian.Cache
{
    public interface ICacheManager<TCacheValue> : ICache<TCacheValue>
    {
        Action<CacheActionEventArgs> OnAdd { get; set; }
        Action<CacheClearEventArgs> OnClear { get; set; }
        Action<CacheClearRegionEventArgs> OnClearRegion { get; set; }
        Action<CacheActionEventArgs> OnGet { get; set; }
        Action<CacheActionEventArgs> OnPut { get; set; }
        Action<CacheItemRemovedEventArgs> OnRemoveByHandle { get; set; }
        Action<CacheActionEventArgs> OnUpdate { get; set; }
        IReadOnlyCacheManagerConfiguration Configuration { get; }
        string Name { get; }
        IEnumerable<BaseCacheHandle<TCacheValue>> CacheHandles { get; }
        TCacheValue AddOrUpdate(string key, TCacheValue addValue, Func<TCacheValue, TCacheValue> updateValue);
        TCacheValue AddOrUpdate(string key, string region, TCacheValue addValue, Func<TCacheValue, TCacheValue> updateValue);
        TCacheValue AddOrUpdate(string key, TCacheValue addValue, Func<TCacheValue, TCacheValue> updateValue, int maxRetries);
        TCacheValue AddOrUpdate(string key, string region, TCacheValue addValue, Func<TCacheValue, TCacheValue> updateValue, int maxRetries);
        TCacheValue AddOrUpdate(CacheItem<TCacheValue> addItem, Func<TCacheValue, TCacheValue> updateValue);
        TCacheValue AddOrUpdate(CacheItem<TCacheValue> addItem, Func<TCacheValue, TCacheValue> updateValue, int maxRetries);
        TCacheValue GetOrAdd(string key, TCacheValue value);
        TCacheValue GetOrAdd(string key, string region, TCacheValue value);
        TCacheValue GetOrAdd(string key, Func<string, TCacheValue> valueFactory);
        TCacheValue GetOrAdd(string key, string region, Func<string, string, TCacheValue> valueFactory);
        CacheItem<TCacheValue> GetOrAdd(string key, Func<string, CacheItem<TCacheValue>> valueFactory);
        CacheItem<TCacheValue> GetOrAdd(string key, string region, Func<string, string, CacheItem<TCacheValue>> valueFactory);
        bool TryGetOrAdd(string key, Func<string, TCacheValue> valueFactory, out TCacheValue value);
        bool TryGetOrAdd(string key, string region, Func<string, string, TCacheValue> valueFactory, out TCacheValue value);
        bool TryGetOrAdd(string key, Func<string, CacheItem<TCacheValue>> valueFactory, out CacheItem<TCacheValue> item);
        bool TryGetOrAdd(string key, string region, Func<string, string, CacheItem<TCacheValue>> valueFactory, out CacheItem<TCacheValue> item);
        TCacheValue Update(string key, Func<TCacheValue, TCacheValue> updateValue);
        TCacheValue Update(string key, string region, Func<TCacheValue, TCacheValue> updateValue);
        TCacheValue Update(string key, Func<TCacheValue, TCacheValue> updateValue, int maxRetries);
        TCacheValue Update(string key, string region, Func<TCacheValue, TCacheValue> updateValue, int maxRetries);
        bool TryUpdate(string key, Func<TCacheValue, TCacheValue> updateValue, out TCacheValue value);
        bool TryUpdate(string key, string region, Func<TCacheValue, TCacheValue> updateValue, out TCacheValue value);
        bool TryUpdate(string key, Func<TCacheValue, TCacheValue> updateValue, int maxRetries, out TCacheValue value);
        bool TryUpdate(string key, string region, Func<TCacheValue, TCacheValue> updateValue, int maxRetries, out TCacheValue value);
        void Expire(string key, ExpirationMode mode, TimeSpan timeout);
        void Expire(string key, string region, ExpirationMode mode, TimeSpan timeout);
        void Expire(string key, DateTimeOffset absoluteExpiration);
        void Expire(string key, string region, DateTimeOffset absoluteExpiration);
        void Expire(string key, TimeSpan slidingExpiration);
        void Expire(string key, string region, TimeSpan slidingExpiration);
        void RemoveExpiration(string key);
        void RemoveExpiration(string key, string region);

    }
}
